function [celltab,xsim]=plot_beta(alph,bet,mingr,stepgr,maxgr); 
% ------------------------------------------------------------------
if nargin < 3 | isempty( mingr ) == 1  
    mingr=0.005; 
    maxgr=1; 
    stepgr=0.005; 
else
    if ( mingr <0 | maxgr > 1 | stepgr > 0.25 ) 
        error('For beta, [mingr,maxgr] should be between 0 and 1, stepgr < 0.25 ') 
    end 
end
meant=alph/(alph+bet); 
vart=alph*bet/(((alph+bet)^2)*(alph+bet+1));
sd=sqrt(vart); 
x=mingr:stepgr:maxgr; 
pdf=betapdf(x,alph,bet); 
%figure; 
plot(x,pdf);
xmm=max(0.01,mingr-2*(stepgr)); 
xlim([xmm maxgr+2*(stepgr)]);
astr=num2str(alph); 
bstr=num2str(bet); 
mstr=num2str(meant); 
sstr=num2str(sd); 
t1=['bet(' astr ',' bstr ')   mean : ' mstr ' sd: ' sstr ]; 
title(t1);
xsim=betarnd(alph,bet,20000,1); 
xsim=sort(xsim); 
med=median(xsim);
per=[0.001 0.01 0.05 0.1 0.5 0.9 0.95 0.99 0.999]; 
perc=betainv(per,alph,bet); 
jj=1; tstr=length(per); 
celltit=cell(tstr,1); 
celltab=cell(tstr,2);
for jj=1:tstr; 
    str_p=sprintf('%1.3f',per(jj)); 
    str_c=sprintf('%3.5f',perc(jj)); 
    celltit(jj)={[str_p,'   ',str_c]};
    celltab(jj,1)={ str_p }; 
    celltab(jj,2)={ str_c };
end 
legend('density',celltit{1},celltit{2},celltit{3},celltit{4},celltit{5},celltit{6},celltit{7},celltit{8},celltit{9})
celladd=[{'1'} {mstr}; {'2'} {sstr}]; 
celltab=[celladd;celltab]; 
